<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>
      Pomelo
    </title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta http-equiv="content-style-type" content="text/css" />
    <meta http-equiv="content-scripte-type" content="text/javascript" />
    <meta name="author" content="netease" />
    <meta name="version" content="1.0" />
    <meta name="keywords" content="pomelo" />
    <link type="text/css" rel="stylesheet" href="css/base.css" />
    <script src="js/lib/build/build.js" type="text/javascript"></script>
    <script type="text/javascript">
      require('boot');
    </script> 
    <script type="text/javascript">
      var pomelo = window.pomelo;
      var host = "127.0.0.1"        //
      // host = "120.55.61.144"
      var port = "3910";
      function show() {
          pomelo.request("connector.entryHandler.getNotify",null, function(data) {
              console.log(data)
          });
      }
      pomelo.on("onMessage",function(data) {
        console.log("onMessage")
        console.log(data)
      })
      pomelo.on("onNotify",function(data) {
        console.log("onNotify")
        console.log(data)
      })
      pomelo.on("disconnect",function(data) {
        // body...
        console.log("disconnect")
      })
      pomelo.on("close",function(data) {
        console.log("close")
      })
      pomelo.on("heartbeat timeout",function(data) {
        // body...
        console.log("heartbeat timeout")
      })
      pomelo.on("io-error",function(data) {
        // body...
        console.log("io-error")
        console.log(data)
      })

      //登录
      var vlogin = function(uid) {
        queryEntry(uid,function(host, port) {
          pomelo.init({
            host: host,
            port: port,
            log: true
          }, function() {
            var route = "connector.entryHandler.visitorEnter";
            pomelo.request(route,{"uid" : uid,inviter : 10001}, function(data) {
              console.log("!!!!!")
              console.log(data)
              if(data.error) {
                console.log(data)
                return;
              }
            });
          });
        });
      }
      var sendData = function(code,params) {
          pomelo.request("connector.entryHandler.sendData", {"code" : code,"params" : params || {}}, function(data) {
              console.log(data)
            }
          );
      }
      //获取游戏配置
      var getGameCfg = function(gameType) {
          sendData("solitary",{type : "getGameCfg",gameType : gameType})
      }
      //设置游戏配置
      var setGameCfg = function(gameType,index,key,value) {
          sendData("solitary",{type : "setGameCfg",gameType : gameType,index : index,key : key,value : value})
      }
      //开始游戏
      var signUp = function(gameType,index) {
          sendData("solitary",{type : "signUp",gameType : gameType,index : index})
      }
      //游戏结束
      var settlement = function(winFlag) {
          sendData("solitary",{type : "settlement",winFlag : winFlag})
      }


      //设置收货地址
      var setAddress = function(address,index) {
          pomelo.request("connector.award.setAddress", {address : address,index : index}, function(data) {
              console.log(data)
            }
          );
      }
      //获取收货地址
      var getAddress = function() {
          pomelo.request("connector.award.getAddress", {}, function(data) {
              console.log(data)
            }
          );
      }
      //玩家申请发货
      var applyDelivery = function(itemId,index) {
          pomelo.request("connector.award.applyDelivery", {itemId : itemId,index : index}, function(data) {
              console.log(data)
            }
          );
      }
      //玩家获取待发货列表
      var getUserWaitDeliverys = function() {
          pomelo.request("connector.award.getUserWaitDeliverys", {}, function(data) {
              console.log(data)
            }
          );
      }
      //玩家获取已发货列表
      var getUserFinishDeliverys = function(begin) {
          pomelo.request("connector.award.getUserFinishDeliverys", {begin : begin}, function(data) {
              console.log(data)
            }
          );
      }
      //管理员获取待发货列表
      var getAllWaitDeliverys = function() {
          pomelo.request("connector.admin.getAllWaitDeliverys", {}, function(data) {
              console.log(data)
            }
          );
      }
      //管理员获取已发货列表
      var getAllFinishDeliverys = function(begin) {
          pomelo.request("connector.admin.getAllFinishDeliverys", {begin : begin}, function(data) {
              console.log(data)
            }
          );
      }
      //管理员确认发货
      var submitDeliverys = function(deliveryId,LogisticCode) {
          pomelo.request("connector.admin.submitDeliverys", {deliveryId : deliveryId,LogisticCode : LogisticCode}, function(data) {
              console.log(data)
            }
          );
      }
      //管理员拒绝发货申请
      var rejectDeliverys = function(deliveryId,reason) {
          pomelo.request("connector.admin.rejectDeliverys", {deliveryId : deliveryId,reason : reason}, function(data) {
              console.log(data)
            }
          );
      }

      //代理系统

      //获取下属玩家
      var getInviterUsers = function(begin) {
          pomelo.request("connector.inviter.getInviterUsers", {begin : begin}, function(data) {
              console.log(data)
            }
          );
      }
      //获取总佣金
      var getAllBrokerage = function() {
          pomelo.request("connector.inviter.getAllBrokerage", {}, function(data) {
              console.log(data)
            }
          );
      }
      //获取佣金记录
      var getBrokerageRecord = function(begin) {
          pomelo.request("connector.inviter.getBrokerageRecord", {begin : begin}, function(data) {
              console.log(data)
            }
          );
      }
      //获取提现记录
      var getWithdrawalRecords = function(begin) {
          pomelo.request("connector.inviter.getWithdrawalRecords", {begin : begin}, function(data) {
              console.log(data)
            }
          );
      }
      var applyWithdrawal = function(value) {
          pomelo.request("connector.award.applyWithdrawal", {value : value,isApp : true}, function(data) {
              console.log(data)
            }
          )
      }
      var queryEntry = function(uid,callback) {
        var route = 'gate.gateHandler.queryClientEntry';
        pomelo.init({
          host: host,
          port: "3910",
          log: true
        }, function(data) {
          console.log("!!!!!")
          console.log(data)
          pomelo.request(route, {
            uid: uid
          }, function(data) {
            console.log("11data !!!!")
            console.log(data)
            pomelo.disconnect();
            if(data.code === 500) {
              console.log(data)
              return;
            }
            callback(host, data.port);
          });
        });
      };
    </script>
  </head>
  <body>
    <div class="g-doc">
      <div class="g-button">
        <input id="test" type="button" value="登录" onclick="vlogin()"/>

      </div>
    </div>
  </body>
</html>
